<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
        xmlns:icecore="http://www.icefaces.org/icefaces/core"
       xmlns:ace="http://www.icefaces.org/icefaces/components"
       xmlns:ice="http://www.icesoft.com/icefaces/component"
       xmlns:c="http://java.sun.com/jsp/jstl/core">      
    <h:head>
        <title><h:outputText>Vorlesung #{lectureBean.lecture.name} Belegwünsche anzeigen</h:outputText></title>
    </h:head>
    <h:body>
        <ui:composition template="WEB-INF/templates/lecture.xhtml">                        
            <ui:define name="content">
                <h:form>
                    <ice:selectManyListbox value="#{tutorEnterScoreBean.choosenGroups}"
                                           rendered="#{!tutorEnterScoreBean.set}">
                        <f:converter converterId="exerciseGroupConverter" />
                        <f:selectItems value="#{tutorEnterScoreBean.groups}" />
                    </ice:selectManyListbox>
                    <br />
                    <ice:commandButton value="Auswählen"
                                       action="#{tutorEnterScoreBean.chooseGroups()}" />
                </h:form>    
            
                <ice:panelGroup>
            <h:form>
                
                <ice:outputText value="Punkte eintragen" />
                <ice:dataTable value="#{lectureBean.lecture.exerciseSheets}"
                               var="sheets"
                               rendered="#{(tutorEnterScoreBean.choosenSheet eq null) and
                                            tutorEnterScoreBean.set}">
                    <ice:column>
                        <ice:commandLink value="#{sheets.name}"
                                         action="#{tutorEnterScoreBean.setChoosenSheet(sheets)}"/>
                    </ice:column>
                </ice:dataTable>
                
                <ice:dataTable rendered="#{tutorEnterScoreBean.choosenSheet ne null}"
                               value="#{tutorEnterScoreBean.userScores}"
                               var="row"
                               varStatus="datStat">
                    <ice:column>
                        <f:facet name="header"><ice:outputText value="Name" /></f:facet>
                        <ice:outputText value="#{row.username}" />
                    </ice:column>
                    <c:forEach begin="0" 
                               end="#{tutorEnterScoreBean.choosenSheet.exercises.size() - 1}"
                               var="index"
                               varStatus="status">

                        <ice:column>
                        <f:facet name="header">
                                <ice:outputText value="#{tutorEnterScoreBean.choosenSheet.exercises.get(index).name}" />
                                <ice:outputText value=" (max. #{tutorEnterScoreBean.choosenSheet.exercises.get(index).maxScore} Punkte)" />
                                <ice:outputText value=", optional"
                                                rendered="#{tutorEnterScoreBean.choosenSheet.exercises.get(index).optional}" />
                        </f:facet>                            
                            <ice:inputText tabindex="#{(datStat.index*(status.end+1)) + status.index+1}"
                                           partialSubmit="true"
                                           value="#{row.cells.get(status.index).score.score}"
                                           valueChangeListener="#{row.cells.get(status.index).scoreChanged}">
                                        <f:validateLongRange minimum="0"
                                                             maximum="#{tutorEnterScoreBean.choosenSheet.exercises.get(index).maxScore}" />
                            </ice:inputText>
                            <ice:selectOneMenu tabindex="#{(datStat.index*(status.end+1)) + status.index + ((datStat.end+1)*(status.end+1)) + 1}"
                                               partialSubmit="true"
                                               value="#{row.cells.get(status.index).score.status}">
                                   <f:selectItems value="#{tutorEnterScoreBean.items}" />
                                   <f:converter converterId="statusConverter" />
                            </ice:selectOneMenu>        
                        </ice:column>
                    </c:forEach>
                </ice:dataTable>
                <br />
                <br />

                    <ice:commandButton value="Speichern"
                                       action="enterScore.jsf" 
                                       rendered="#{tutorEnterScoreBean.choosenSheet ne null}"/>
                    <br />
                    <ice:commandButton value="Zurück"
                                     action="#{tutorEnterScoreBean.setChoosenSheet(null)}"
                                     rendered="#{tutorEnterScoreBean.choosenSheet ne null}"/>
            </h:form>
                    </ice:panelGroup>    
            </ui:define>
        </ui:composition>
    </h:body>
</html>